package com.lg.erp.controller.zhangchaofu;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.zhangchaofu.ZCFTWare;
import com.lg.erp.entity.zhangchaofu.TWarning;
import com.lg.erp.service.zhangchaofu.StockEarlyWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StockEarlyWarningController {

    @Autowired
    private StockEarlyWarningService stockEarlyWarningService;

    /**
     * 查找仓库和货区信息
     * @return
     */
    @GetMapping("stockEarlyWarning-ware")
    public JsonResult findStockEarlyWarningWareAndWarehouse(){
        List<ZCFTWare> wareList =stockEarlyWarningService.findStockEarlyWarningWareAndWarehouse();
        return new JsonResult(1,"ok",wareList);
    }

    /**
     * 查询预警的商品
     * @param current
     * @return
     */
    @GetMapping("/stockEarlyWarning/{current}")
    public JsonResult findStockEarlyWarningMessageProduct(@PathVariable Integer current){
        Page<TWarning> page=new Page<>(current,10);
        IPage<TWarning> pages =stockEarlyWarningService.findStockEarlyWarningMessageProductPage(page);
        return new JsonResult(1,"ok",pages);
    }

    /**
     * 修改预警值
     * @param warning
     * @return
     */
    @ResponseBody
    @PutMapping("/stockEarlyWarning")
    public JsonResult modifyStockEarlyWarningMessageProduct(@RequestBody TWarning warning){
        stockEarlyWarningService.modifyStockEarlyWarningMessageProduct(warning);
        return new JsonResult(1,"ok",null);
    }

    /**
     * 根据输入的产品关键字查找对应的产品
     * @param productName
     * @return
     */
    @ResponseBody
    @GetMapping("/stockEarlyWarning-product/{productName}")
    public JsonResult findStockEarlyWarningMessageProduct(@PathVariable("productName") String productName){
        List<TWarning> warningList=stockEarlyWarningService.findStockEarlyWarningMessageProduct(productName);
        return new JsonResult(1,"ok",warningList);
    }

    @GetMapping("/stockEarlyWarning-ware-product/{wareId}")
    public JsonResult findStockEarlyWarningMessageWareProduct(@PathVariable("wareId") String wareId){
        List<TWarning> warningList=stockEarlyWarningService.findStockEarlyWarningMessageWareProduct(wareId);
        return new JsonResult(1,"ok",warningList);
    }
}
